'''
Created on 2013-5-3

@author: darcywang
'''

import os
import re
from urlparse import urlparse
def getItemId(query):
    print query
    values = urlparse(query).query.split("&")
    print values
    for item in values:
        #print "split item " + item
        kvs = item.split("=")
        if kvs[0] in ["id","itemId","item_id"] and len(kvs) == 2 and re.match(r"\d+",kvs[1]):
            return kvs[1]
    return None
if __name__ == '__main__':
    print os.getcwd()
   # print urlparse.urlparse("http://ju.taobao.com/tg/home.htm?id=20164423374&spm=1.1.0.1")
    print getItemId("http://ju.taobao.com/tg/home.htm?id=20164423374&spm=1.1.0.1")